package com.langxin.site.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.langxin.site.biz.TourBiz;
import com.langxin.site.model.PageInfo;
import com.langxin.site.model.TourInfo;
import com.langxin.site.model.vo.QueryVo;

/**
 * 旅游action
 * @author guqj
 *
 */
@Controller
@RequestMapping("/lvyou")
public class TourAction {

	@Autowired
	private TourBiz      tourBiz;
	
	
	/**
	 * 旅游
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String tour(Model model, QueryVo queryVo, PageInfo<TourInfo> pageInfo){
		model.addAttribute("gifts", tourBiz.queryGifts(4));
		tourBiz.queryPage(queryVo, pageInfo);
		if(pageInfo.getRecords() == null || pageInfo.getRecords().size() == 0){
			return "redirect:/lvyou";
		}
		model.addAttribute("pageInfo", pageInfo);
		return "tour/tour_list.jsp";
	}
	
	/**
	 * 旅游详情
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	public String tourDetail(Model model, @PathVariable Integer id){
		model.addAttribute("gifts", tourBiz.queryGifts(4));
		TourInfo tourInfo = tourBiz.queryById(id);
		if(tourInfo == null){
			return "error/404.jsp";
		}
		model.addAttribute("tour", tourInfo);
		return "tour/tour_detail.jsp";
	}
}
